package cn.csc.module.order.mq.producer.hzh;

import cn.csc.framework.mq.core.bus.AbstractBusProducer;
import cn.csc.module.order.dal.dataobject.order.OrderDO;
import cn.csc.module.order.mq.message.OrderForHzhMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageConst;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 商家发货消息，发送给park-pc-backend
 * topic: order_deliver
 * @author liuchuang
 * @version 1.0
 * @date 2024/7/30 9:42
 * @modify
 */
@Slf4j
@Component
public class OrderDeliverForHzhProducer extends AbstractBusProducer {

    @Resource
    private StreamBridge streamBridge;

    /**
     * 发送 {@link OrderForHzhMessage} 消息
     *
     * @param order 订单
     */
    public Boolean sendOrderDeliverMessage(OrderDO order, Long currentUserId) {
        OrderForHzhMessage orderMessage = new OrderForHzhMessage();
        orderMessage.setCompanyId(order.getShopId())
                .setShopName(order.getShopName())
                .setSpuName(order.getSpuName())
                .setUserId(currentUserId)
                .setCustUserId(order.getUserId().longValue())
                .setCommonId(order.getId().longValue());

        Message<OrderForHzhMessage> message = MessageBuilder.withPayload(orderMessage)
                // 设置ORIGIN_MESSAGE_ID
                .setHeader(MessageConst.PROPERTY_ORIGIN_MESSAGE_ID, order.getId())
                .build();
        return streamBridge.send("orderDeliverHzh-out-0", message);
    }


}
